// Copyright (C) 2011  Andrew H. Chan
// 
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

#include "basic_includes.h"
#include "typedefs.h"
#include "util.h"
#include "input_data.h"
#include "sampler.h"

using namespace std;

gsl_rng *rg = NULL;

int main(int argc, char* argv[]) {
    if(argc < 3) {
        cout << "\nusage:  phasing data_file iterations" << endl;
        return 1;
    }

    // read in seed
    uint seed;
    ifstream in("seed");    
    if(in.is_open()) {
        in >> seed; 
    } else {
        seed = time(NULL);
    }
    in.close();

    // init random number generator
    rg = gsl_rng_alloc(gsl_rng_taus);
    gsl_rng_set(rg, seed);

    string data_file = argv[1];
    Input_data input;
    input.read_input(data_file);

    uint iterations = atoi(argv[2]);

    Sampler sampler(input);
    sampler.gibbs_sample(iterations);

    // write out seed
    ofstream out("seed");
    if(out.is_open()) {
        out << gsl_rng_get(rg) << '\n';
    }
    gsl_rng_free(rg);
    return 0;
}
